/**
 * Created by ying on 16-9-1.
 */
function Cart(){
    this.goods_info=JSON.parse(localStorage.getItem("data")) || {};
}
Cart.prototype.get_sum_count=function(){
    var sum_count=0;
    _.each(this.goods_info,function(info){
        sum_count+=Number(info.count);
    })
    return sum_count;
}
Cart.prototype.get_sum_money=function(){
    var sum_money=0;
    _.each(this.goods_info,function(info){
        sum_money+=info.actually;
    })
    return sum_money;
}
Cart.prototype.get_save_money=function(){
    var save_money=0;
    _.each(this.goods_info,function(info){
        save_money+=info.price*info.pro_count;
    })
    return save_money;
}

Cart.prototype.get_goods_info=function(item){
    if(item.name in this.goods_info){
        this.goods_info[item.name].count++;
    }else{
        item.count=1;
        this.goods_info[item.name]=item;
    }
}
Cart.prototype.updata_goods_info=function(item,num,classification,name,price,unit,count){
    var item=new Item(item,classification,name,price,unit,count);
    var new_count=Number(item.count)+num;
    item.change_count(new_count,this.goods_info,item);
    if(this.goods_info[item.name].count==0){
        delete(this.goods_info[item.name])
    }else{
        var pro=new Promotion();
        pro.get_pro_count(item,this.goods_info);
        var goods_info=item.get_subtotal(this.goods_info);
    }
}